**********************************************************************
Items
**********************************************************************

There are 467 items in Lufia 2. Most of their properties are stored in 
what I call the "Item Compendium".

-----------------------------------------------------------------------
Item names
-----------------------------------------------------------------------

[$0F49E8 -> $0F5FCB]:  item names

Item names are 12 bytes long. They are stored one after the other, 
without any separation byte.

-----------------------------------------------------------------------
Item data - the "Item Compendium"
-----------------------------------------------------------------------

[$0B5169 -> $0B550E]:  pointers to data at [$0B550F]
                       (2 bytes, little-endian (i.e. "least significant 
                                                      byte first"))

                       934 bytes => 467 pointers.
                       Add $0B5169 to the pointers to find the offsets
                       of the Item Compendium "entries".

                       Example:
                       [$0B5169 -> $0B516A]: $A6 03
                       => pointer: $03A6
                       => offset: $03A6 + $0B5169 = $0B550F
                       => The first Item Compendium entry starts 
                          at offset [$0B550F]

[$0B550F -> $0B7CDC]:  "Item Compendium"

                       467 entries:
                       [$0B550F]:  No equip    
                       [$0B551C]:  Charred newt
                       ...
                       [$0B7CBD]:  Tag candy   
                       [$0B7CCE]:  Last        

- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 
Format of the Item Compendium entries:
- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 

  13 "common properties bytes" 
+ a variable number of "additional properties bytes" 
+ a variable number of "effect bytes"


Start offset of the Monster Compendium entry = offset [+$0000]

- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 
"Common properties bytes":
- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 

  Byte 0:           "Usability"
  Byte 1:           ???
  Byte 2:           Targetting mode
  Byte 3:           Icon
  Byte 4:           Sprite
  Bytes 5 and 6:    GP cost
  Byte 7:           "Equipability"
  Byte 8:           Who can be equipped with the item
  Bytes 9 and 10:   "additional properties" flags
  Bytes 11 and 12:  $00 00 for all items

[+$0000]
Byte 0: "Usability"

        Each bit of this byte is a flag. These flags define some of the 
        most important properties of items, hence defining their type and 
        usability. The state of the flags for a given item also determines 
        its "rank" (position) in the inventory after the use of the Sort
        option of the Party Status screen Item menu.

        bit 0: 1 => Is one of the "most useful items". 
                    For items that should stay at the top of the inventory
                    (HP/MP recovery potions, ...)

        bit 1: 1 => Equipable item.
                    This flag MUST be set for an item to be equipable: 
                    if it's not set, the item name doesn't appear 
                    in the Equip menu. See also: byte 7.
                    Also set for dungeon items ('Hook', ...).

        bit 2:      (not used - always 0.
                    If set, places the item between "equipable" and 
                    "fruit" items when the inventory is sorted.)

        bit 3: 1 => Cursed item.
                    Only used for equipable items. Once equipped, cursed 
                    equipable items can't be removed and their name appears 
                    in red (instead of white) in the Equip menu.

        bit 4: 1 => "fruit item" 
                    Fruits occupy the lowest places in the inventory. 

        bit 5: 1 => Can't be dropped/sold. Set for:
                    - scenario items
                    - dungeon items ('Hook', ...)
                    - 'Jewel sonar'
                    - Iris Treasures
                    - 'Dragon egg'
                    - 'Dual blade'

        bit 6: 1 => Usable at Party Status screen.
                    The name appears in black (instead of gray) in the 
                    Party Status screen Item menu).
                    Ex.: 'Potion', 'Spell potion'
                    Not for weapons.

        bit 7: 1 => Usable as an item (not as a weapon) during battle.
                    The name appears in white (instead of blue) in the 
                    Battle screen Item menu.
                    Ex.: 'Potion', 'Shriek'

        Here's the list of the values of byte 0 actually used in the game:

        $00 (b0000 0000) => (no flag set)
                            - 'No equip'
                            - 'Green tea', 
                            - coins ('1 coin', '10 coin set', ...)

        $02 (b0000 0010) => Equipable item.
                            For all non-cursed equipable items 
                            except the 'Dual blade'.

        $0A (b0000 1010) => Cursed equipable item.

        $10 (b0001 0000) => Fruit.

        $20 (b0010 0000) => Can't be dropped/sold.
                            - 'Dragon egg'
                            - Iris treasures
                            - scenario items

        $22 (b0010 0010) => Equipable item, can't be dropped/sold.
                            - 'Dual blade'
                            - dungeon items ('Hook', ...)

        $40 (b0100 0000) => Usable as an item at Party Status screen.
                            - 'Escape'
                            - 'Warp'
                            - 'Providence'

        $41 (b0100 0001) => Usable at Party Status screen, 
                            very useful. 
                            - 'Life potion', 'Spell potion', 'Brave'
                            - 'Curselifter'

        $60 (b0110 0000) => Usable at Party Status screen, 
                            can't be dropped/sold.
                            - 'Jewel sonar'.

        $80 (b1000 0000) => Usable as an item (not as a weapon) 
                            during battle.
                            - 'Awake', 'Shriek', 'Mystery pin'
                            - 'Power gourd', 'Mind gourd', 'Magic guard'
                            - balls ('Sleep ball', ...)
                            - boomerangs ('Boomerang', ..., 'Dragon tooth')
                            - 'Flame charm', 'Zap charm', 'Magic lamp'
                            - 'Tag candy'

        $C1 (b1100 0001) => Usable as an item at Party Status screen 
                            as well as during battle,
                            very useful.
                            - HP/MP recovery items
                              ('Charred newt', 'Ex-Magic', 'Statue', ...)
                            - 'Regain', 'Miracle'
                            - 'Antidote'
                            - ciders ('Pear cider', ...)

        Items "rank":
        The position an item will occupy in the inventory after the use 
        of the Sort option depends of several flags of byte 0. It also 
        depends of other bytes. The following "rank" list is not 100 % 
        complete/accurate.

        Top of the inventory    "most useful items"
                                items usable at Party Status screen
                                items usable during battle
                                items that cannot be dropped
                                equipable items
        Bottom                  fruits

                          - - - - - - - - - - - 

[+$0001]
Byte 1: ???

        The use of this byte is unkown.
        Here's a list of all encountered values:

        $01 for Arrow
        $03 for Hook
        $04 for Bomb
        $06 for Fire arrow
        $07 for Hammer

        Note: to invert the values of two dungeon items inverts 
              their positions in the "dungeon item ring".

        $20 for S-fire ring,
                S-water ring,
                S-ice ring,
                S-thun ring

        $40 for a lot of "good" equipment items
            (items that have an IP, an "elemental power", ...)

        $60 for a lot of "good" equipment items, including (but not 
            limited to) all the blue chest items.
            Also for 'Curselifter', 'Providence' and 'Tag candy'

        $70 for Egg sword,
                Pearl armor,
                Pearl shield,
                Pearl helmet,
                Egg ring

        $80 for all the fruits

        $00 for all the other items (including the 'Dual blade')

        Notes: - generally speaking, it seems that more "valuable" 
                 items have a higher value for byte 1.
               - the value of this byte doesn't *seem* to be related to the 
                 "nutritional" value of the object for Capsule Monsters.

                          - - - - - - - - - - - 

[+$0002]
Byte 2: Targetting mode

        $00 => You can't/don't have to target
               (bows, boomerangs, ...)

        $01 => You must target one or several allies
               (the 'Statue' is the only item having this property)

        $02 => You must target one (and only one) ally
               ('Potion', 'Mystery pin', ...)

        $81 => You must target one or several enemies
               (the Freeze bow is the only weapon having this property)

        $82 => You must target one (and only one) enemy
               (most weapons)

        !!! This byte does not affect the effect of the weapon
            (ex.: Arty's bow (targetting mode: $00) will still attack all 
            enemies even if this byte is set to $81 or $82)

                          - - - - - - - - - - - 

[+$0003]
Byte 3: Icon

        The icon that appears to the left of the item name in 
        the Item menu.

        $10 => no icon
        $E0 => Sword
        $E1 => Armor
        $E2 => Shield
        $E3 => Helmet
        $E4 => Shoe (not used by any existing item)
        $E5 => Ring
        $E6 => Potion
        $E7 => Key
        $E8 => Whip
        $E9 => Staff
        $EA => Spear
        $EB => Arrow (for bows and boomerangs)
        $EC => Jewel
        $ED => Ax
        $EE => Ball ('Sleep ball', 'Confuse ball', ...)
        $EF => Wrench (for tools)

        !!! This byte affects only the icon, not the usability/equipability 
            of the items (see byte 0 and 7)

                          - - - - - - - - - - - 

[+$0004]
Byte 4: Sprite

        The sprite that represents the item when you obtain it by opening 
        a chest, when someone gives it to you (scenario items), ...
        There's a lot of item sprites. The following list is not complete.

        $00 => Coins ('1 coin', ... 
                      Also used for some items not found in chests,
                      like the 'Dual blade')
        $01 => Sword ('Gladius', ...)
        $02 => Armor ('Metal mail', ...)
        $03 => Shield
        $04 => Helmet
        $05 => VIP card
        $06 => Ring
        $08 => Key
        $09 => Whip
        $0A => Rod
        $0B => Spear
        $0C => Bracelet
        $0D => Jewel ('Evil jewel', 'Magma rock', ...)
        $0E => Ax
        $0F => Ball
        $10 => Wrench
        $11 => Gloves
        $12 => Dragon Egg
        $13 => Mace ('Morning star', ...)
        $15 => Boomerang
        $17 => Fruit
        $18 => Bow
        $1B => Dress ('Quilted silk', ...)
        $1C => Scroll (for spells in the Ancient Cave. Not used for items)
        $1D => Hat ('Blue beret')
        $20 => Wing ('Escape', 'Warp', 'Providence')
        $21 => Tiara ('Fury ribbon', ...)
        $22 => Knife
        $40 => Bomb
        $41 => Hook
        $42 => Hammer
        $43 => Arrow
        $44 => Fire arrow
        $45 => Hourglass ('Reset' spell. Not used for items)

                          - - - - - - - - - - - 

[+$0005, +$0006]
Bytes 5 and 6:
        GP cost (2 bytes, little-endian).

        Example:
        - Bytes 5 and 6 of the 'Silver sword':
          $48 71 => GP cost = $7148 = 29000 GP

        The following items have a cost of 0 GP:
        - 'No equip'
        - 'Dragon egg'
        - 'Dual blade'
        - Iris Treasures,
        - Scenario items.

                          - - - - - - - - - - - 

[+$0007]
Byte 7: "Equipability"

        Each bit of this byte is a flag. Only one bit can be set for 
        each item. if 2 or more bits are set, only the least significant 
        one will be taken into account.

        $00 (b00000000) => non equipable
        $01 (b00000001) => equipable as Weapon
        $02 (b00000010) => equipable as Armor
        $04 (b00000100) => equipable as Shield
        $08 (b00001000) => equipable as Helmet
        $10 (b00010000) => equipable as Ring
        $20 (b00100000) => equipable as Jewel

        Note: bit 1 of byte 0 must be set for an item to be equipable.

                          - - - - - - - - - - - 

[+$0008]
Byte 8: Who can be equipped with the item

        Each bit of this byte is a flag.

        bit 0: 1 => Maxim
        bit 1: 1 => Selan
        bit 2: 1 => Guy
        bit 3: 1 => Artea
        bit 4: 1 => Tia
        bit 5: 1 => Dekar
        bit 6: 1 => Lexis
        bit 7: (not used - 0 for all existing items)

        Examples:

        - Byte 8 of all the "non-equipable" items:
          $00 = b00000000 => Nobody

        - Byte 8 of the 'Dual blade':
          $01 = b00000001 => Maxim only

        - Byte 8 of the 'Bunny ears':
          $1A = b00011010 => Selan, Artea and Tia

        - Byte 8 of the 'Mystery ring':
          $7F = b01111111 => All

                          - - - - - - - - - - - 

[+$0009, +$000A]
Bytes 9 and 10:
        "additional properties" flags

        Each bit of these bytes is a flag. 
        For each set flag, there will be 2 "additional properties bytes" 
        (if none of the flags are set, there will be no "additional 
        properties bytes").

        Byte 9:

        bit 0: 1 => Has an "Item effect" at Party Status screen.
                    Some item effects: 
                    - HP/MP recovery ('Charred newt', ...)
                    - warp ('Escape', 'Warp', ...)
                    - ...
                 => A pointer to the "item effect bytes" is stored on 
                    2 "Additional properties bytes" (little-endian). 
                    Add the start offset of the Item Compendium entry to
                    find the offset of the item effect bytes.

                    Example:
                    - Byte 9 for the 'Charred newt': $03 (b00000011)
                      => bit 0 is set
                      => the 'Charred newt' has an "Item effect" at 
                         Party Status screen.

                         "Additional properties bytes" corresponding to 
                         bit 0: $15 00
                         => pointer to the "effect bytes": $0015

                      Start offset of the 'Charred newt' Item 
                      Compendium entry: [$0B551C]
                      => offset of the "effect bytes":
                         $0015 + $0B551C = $0B5531
                      => the bytes defining the effect of the 
                         'Charred newt' when it's used at the Party Status 
                         screen start at offset [$0B5531].

        bit 1: 1 => Has an "item effect" during battle.
                    Not for equipable items (see bit 2).
                    Some item effects: 
                    - HP/MP recovery
                    - damage (boomerangs, ...)
                    - ...
                 => A pointer to the "item effect bytes" is stored on 
                    2 "Additional properties bytes" (little-endian). 
                    Add the start offset of the Item Compendium entry to
                    find the offset of the item effect bytes.

        bit 2: 1 => Has a "Weapon special effect".
                    For weapons, 'Undead ring', 'Sea ring', 'Dragon ring'.
                    Some weapon special effects: 
                    - enhanced critical hit rate
                    - "elemental attacks" (Fire, Thunder, ...)
                    - chances of causing Confusion, Sleep, 
                      Instant Death, ...
                    - ...
                 => A pointer to the "weapon effect bytes" is stored on 
                    2 "Additional properties bytes" (little-endian). 
                    Add the start offset of the Item Compendium entry to
                    find the offset of the weapon effect bytes.

        bit 3: 1 => Has an "Armor special effect".
                    For protective equipment (armors, shields, helmets, 
                    rings, ...).
                    Some armor special effects: 
                    - "elemental protection" (Fire, Thunder, ...)
                    - protection against Confusion, Sleep, 
                      Instant Death, ...
                    - ...
                 => A pointer to the "armor effect bytes" is stored on 
                    2 "Additional properties bytes" (little-endian). 
                    Add the start offset of the Item Compendium entry to
                    find the offset of the armor effect bytes.

        bit 4: 1 => Increases ATP.
                    For equipable items only, not for "potions" 
                    (see bit 0 and 1).
                 => The ATP increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 5: 1 => Increases DFP.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The DFP increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 6: 1 => Increases STR.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The STR increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 7: 1 => Increases AGL.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The AGL increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        Byte 10:

        bit 0: 1 => Increases INT.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The INT increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 1: 1 => Increases GUT.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The GUT increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 2: 1 => Increases MGR.
                    For equipable items only, not for "potions"
                    (see bit 0 and 1).
                 => The MGR increasment is stored on 2 "Additional 
                    properties bytes" (little-endian).

        bit 3: 1 => (not used - 0 for all existing items)

        bit 4: 1 => (not used - 0 for all existing items)

        bit 5: 1 => Animation when used during battle.
                    For weapons, "potions", ...
                 => The animation number is stored on 2 "Additional 
                    properties bytes" (little-endian).
                    Some animation numbers:
                    $0000 => No battle animation
                             The character doesn't move; no sound; 
                             no "slashing" effect (but the attack inflicts 
                             damage).
                             For 'Last' and 'RAN-RAN step'.
                    $0001 => "Sword" animation
                             For all swords (except 'Frypan' and 'Last') 
                             and daggers.
                    $0003 => "Rod" animation
                             For all rods and maces + 'Frypan'.
                    $0005 => "Bow" animation
                             For all bows.
                    $0007 => "Spear" animation
                             For all spears + 'Superdriver'.
                    $0009 => "Whip" animation
                             For all whips.
                    $000B => "Tool animation
                             For all tools except 'Superdriver'.
                    $000D => "Ax" animation
                             For all axes.
                    $000F => "Punch" animation
                             For attacks without an equipped weapon.

                    $0013 => 'Flash' spell animation
                    $0014 => 'Bolt' spell animation
                    ...
                    $0033 => 'Zap spell' animation
                    $0091 => 'Dark Fry' animation

        bit 6: 1 => ???
                 => 2 "Additional properties bytes": $64 00
                    Note: the value of these 2 bytes doesn't seem to have 
                          an effect on the animation displayed when the 
                          item is used at Party Status screen.

        bit 7: 1 => Has an IP effect.
                    For equipable items only.
                 => The IP number is stored on 2 "Additional 
                    properties bytes" (little-endian).
                    Some IP numbers:
                    $0001 => Repeat attack
                    $0002 => Iron kick
                    $0003 => Mirror block
                    ...
                    $002D => Wave motion
                    ...
                    $00A8 => Octo-strike
                    $00A7 => Double slash
                    $00A8 => Ancient power

                          - - - - - - - - - - - 

[+$000B, $000C]
Bytes 11 and 12:
        $00 00 for all items

- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 
"Additional properties bytes"
- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 

The "Additional properties bytes" corresponding to the "Additional 
properties flags" (bytes 9 and 10) are stored in the following order:
[2 bytes for byte  9, bit 0], 
[2 bytes for byte  9, bit 1], 
...
[2 bytes for byte  9, bit 6], 
[2 bytes for byte  9, bit 7], 
[2 bytes for byte 10, bit 0], 
[2 bytes for byte 10, bit 1], 
...
[2 bytes for byte 10, bit 6], 
[2 bytes for byte 10, bit 7].

Example: 'Hi-Potion' [$0B556C]
- Byte  9: $03 (b00000011)
           bit 0: 1 => Has an "Item effect" at Party Status screen.
           bit 1: 1 => Has an "item effect" during battle.
- Byte 10: $60 (b01100000)
           bit 5: 1 => Animation when used during battle.
           bit 6: 1 => ???
=> the 'Hi-Potion' has 8 (= 4 * 2) additional properties bytes:
   15 00 1D 00 61 00 64 00
   - $15 00: the "Item effect at Party Status screen" bytes start at 
             offset [$0B556C + $0015]
   - $1D 00: the "Item effect at Party Status screen" bytes start at 
             offset [$0B556C + $001D]
   - $61 00: animation when used during battle: animation number $0061
   - $64 00: ???


Important remark about the "stats increasment bytes":

When an item increases STR, it also increases ATP, even if bit 4 of 
byte 9 is not set:

  total ATP increasment granted by an item 
  = ATP incr (if bit 4 of bytes 9 is set)
  + STR incr (if bit 6 of bytes 9 is set)

Similarly, when an item increases STR and/or AGL, it also increases DFP, 
even if bit 5 of byte 9 is not set:

  total DFP increasment granted by an item 
  = DFP incr 
  + (STR incr + AGL incr) / 2

Example: 'lion fang' [$0B7557]

- Byte  9: $C0 (b11000000)
           bit 4: 0 => Doesn't (explicitely) increase ATP.
           bit 5: 0 => Doesn't (explicitely) increase DFP.
           bit 6: 1 => Increases STR.
           bit 7: 1 => Increases AGL.

STR incr bytes: $0F 00 => STR incr = 15
AGL incr bytes: $0A 00 => AGL incr = 10

=> total ATP incr = ATP incr + STR incr
                  = 0 + 15
                  = 15

=> total DFP incr = DFP incr + (STR incr + AGL incr) / 2
                  = 0 + (15 + 10) / 2
                  = 12.5
                  ~= 12

=> Increasments of the 'Lion fang': ATP +15, DFP +12, STR +15, AGL +10

Other example: 'Fire dagger' [$0B5C2A]

ATP incr = 50
DFP incr = 0
STR incr = 6
AGL incr = 0
=> total ATP incr = 56
   total DFP incr = 3
=> Increasments of the 'Fire dagger': ATP +56, DFP +3, STR +6

- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 
"Effect bytes"
- - - - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - 

...

-----------------------------------------------------------------------
Item descriptions
-----------------------------------------------------------------------

[$0B8200 -> $0B85FF]:  pointers to item descriptions
                       (2 bytes, little-endian)

[$0B87B4 -> $0BB2A0]:  item/spell/IP descriptions

